/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2512.java
 * @Author : WangRuoyu
 * @Date 2023/1/11 10:20
 */

package leetcode;

import java.util.*;

public class Q2512 {
    public List<Integer> topStudents(String[] positive_feedback, String[] negative_feedback, String[] report, int[] student_id, int k) {
        List<Integer> res = new ArrayList<>();

        HashSet<String> positive = new HashSet<>(Arrays.asList(positive_feedback));
        HashSet<String> negative = new HashSet<>(Arrays.asList(negative_feedback));

        List<int[]> scores = new ArrayList<>(k);

        for (int i = 0; i < report.length; i++) {
            int score = 0;
            String[] strs = report[i].split(" ");
            for (String str : strs) {
                if (positive.contains(str)) {
                    score += 3;
                } else if (negative.contains(str)) {
                    score -= 1;
                }
            }
            scores.add(new int[]{score, student_id[i]});
        }

        Collections.sort(scores, (a, b) -> a[0] == b[0] ? a[1] - b[1] : b[0] - a[0]);
        for (int[] score : scores) {
            System.out.println(Arrays.toString(score));
        }

        for (int i = 0; i < k; i++) {
            res.add(i, scores.get(i)[1]);
        }

        return res;
    }

    public static void main(String[] args) {
        Q2512 sl = new Q2512();
        String[] positive_feedback = {"smart", "brilliant", "studious"};
        String[] negative_feedback = {"not"};
        String[] report = {"this student is not studious", "the student is smart"};
        int[] student_id = {1, 2};
        int k = 2;
        System.out.println(sl.topStudents(positive_feedback, negative_feedback, report, student_id, k));
    }
}
